﻿using UnityEngine;
using System.Collections;

public class shootable : MonoBehaviour {

	public int hp = 10;
	public GameObject hit_fx;
	public GameObject die_fx;
	public GameObject bonus_item;

	void OnCollisionEnter2D(Collision2D c)
	{
		if (c.gameObject.tag == "bullet") 
		{
			hp --;

			if(hit_fx != null)
			{
				GameObject clone = Instantiate(hit_fx,
			               transform.position,
			               transform.rotation)as GameObject;
				Destroy (clone, 1f);
			}
		}

		if (hp <= 0)
		{
			Destroy (gameObject);

			// kuolemisefekti
			if(die_fx != null)
			{
				GameObject clone = Instantiate(die_fx,
				           transform.position,
				           transform.rotation)as GameObject;
				Destroy (clone, 1f);
			}
			// pudotetaan bonus itemi
			if(bonus_item != null)
			{
				GameObject clone = Instantiate(bonus_item,
				           transform.position,
				           transform.rotation)as GameObject;
			}
		}

	}

}
